<?php

/**
 * @param $id
 * @return string
 */
function getCateNameByCateId($id )
{
    if($id==0){
        return '顶级分类';
    }
    return \App\Cate::find($id)->name;
}

function getCates()
{
    $cates = \App\Cate::select(DB::raw('*,concat(path,",",id) as paths'))->orderBy('paths')->get();
    foreach($cates as $key=>$val){
        $tmp = count(explode(',', $val->path));
        $prefix = str_repeat('|-------', $tmp-1);
        $val->name = $prefix.$val->name;
    }
    return $cates;
}